package com.sanwu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sanwu.dto.ManagerDto;
import com.sanwu.entity.Business;
import com.sanwu.mapper.BusinessMapper;
import com.sanwu.service.ManagerService;
import com.sanwu.vo.AjaxResult;
import com.sanwu.vo.CommonMessage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hgh
 * @date 2025/3/11
 * @apiNote
 */

@Service
public class ManagerServiceImpl extends ServiceImpl<BusinessMapper, Business> implements ManagerService {

    @Resource
    private BusinessMapper businessMapper;

    /**
     * 查看所有的业务
     *
     * @param managerDto
     * @return
     */
    @Override
    public List<Business> queryAllBusiness(ManagerDto managerDto) {
        LambdaQueryWrapper<Business> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Business::getIsDelete, 0);

        //完成状态（0：未完成；1：完成）
        queryWrapper.eq(managerDto.getCompleteStatus() != null
                , Business::getCompleteStatus
                , managerDto.getCompleteStatus());

        List<Business> businesses = businessMapper.selectList(queryWrapper);
        return businesses;
    }

    /**
     * 查看业务详情
     *
     * @param managerDto
     * @return
     */
    @Override
    public AjaxResult businessDetail(ManagerDto managerDto) {
        LambdaQueryWrapper<Business> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Business::getIsDelete, 0);
        queryWrapper.eq(Business::getId, managerDto.getId());
        List<Business> businesses = businessMapper.selectList(queryWrapper);

        if (businesses == null || businesses.size() <= 0) {
            return new AjaxResult(CommonMessage.error, "查询失败");
        }

        return new AjaxResult(CommonMessage.success, "查询成功", businesses.get(0));
    }

    /**
     * 短信验证码登录
     *
     * @param phoneMessage
     * @return
     */
    @Override
    public AjaxResult phoneMessageLogin(String phoneMessage) {
        return new AjaxResult(200, "登录成功");
    }

    /**
     * 发送短信验证码
     *
     * @return
     */
    @Override
    public AjaxResult sendCheckCode() {
        return new AjaxResult(200, "", "123456");
    }
}
